/*
 * Copyright (C) 2012-2013  Romain DUBOIS
 * 
 * This file is part of NeMoS - Network and Modular Software
 * 
 * NeMoS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * NeMoS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with NeMoS.  If not, see <http://www.gnu.org/licenses/>.
 */
package nemos.remote.rsa.message.data;

/**
 * FrameworkMessage : The framework message.
 * 
 * <p>
 * A client sends this message to notify the server the frameworks it
 * represents.
 * </p>
 * 
 * @author Romain DUBOIS
 */
public class FrameworkMessage extends Message {

    /** Serial version */
    private static final long serialVersionUID = 1L;

    /** The represented framework */
    private String mFrameworkUUID;
    /** The action */
    private EFrameworkAction mAction;

    /**
     * Constructor
     */
    public FrameworkMessage() {
        super();
    }

    /**
     * Constructor
     * 
     * @param pFrameworkUuid
     *            The represented framework
     * @param pAction
     *            The action on the framework
     */
    public FrameworkMessage(final String pFrameworkUuid, final EFrameworkAction pAction) {
        super();
        mFrameworkUUID = pFrameworkUuid;
        mAction = pAction;
    }

    /**
     * Get the represented framework UUID.
     * 
     * @return The framework UUID
     */
    public String getFrameworkUUID() {
        return mFrameworkUUID;
    }

    /**
     * Get the framework action.
     * 
     * @return The framework action
     */
    public EFrameworkAction getAction() {
        return mAction;
    }

    /**
     * {@inheritDoc}
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        final StringBuilder lBuilder = new StringBuilder(super.toString());
        lBuilder.append('[');
        switch (mAction) {
            case JOIN:
                lBuilder.append('+');
                break;

            case KICKED:
                lBuilder.append('~');
                break;

            case LEAVE:
                lBuilder.append('-');
                break;

            default:
                lBuilder.append('?');
        }
        lBuilder.append(mFrameworkUUID);
        lBuilder.append(']');
        return lBuilder.toString();
    }

    /**
     * Test if the framework has been added.
     * 
     * @return If the framework has been added
     */
    public boolean isAdded() {
        return mAction == EFrameworkAction.JOIN;
    }

    /**
     * Test if the framework has been removed.
     * 
     * @return If the framework has been removed
     */
    public boolean isRemoved() {
        return mAction == EFrameworkAction.KICKED || mAction == EFrameworkAction.LEAVE;
    }
}
